///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_IMAGE_CPICTURE_H__
#define _BUOLA_IMAGE_CPICTURE_H__

#include <buola/image/cimage.h>
#include <buola/image/csurface.h>
#include <buola/image/format.h>
#include <buola/image/io.h>

namespace buola { namespace img {

class CPicture
{
    struct SImpl : public UShared
    {
        CAnyImage mImage;
    };

public:
    CPicture() {}

    CPicture(CAnyImage &&pImage)
        :   mImpl(new SImpl)
    {
        mImpl->mImage=std::move(pImage);
    }

    explicit CPicture(const io::CURI &pURI,EImageFormat pFormat=FORMAT_ANY,const CSize_i &pSize=nUndefined)
        :   mImpl(new SImpl)
    {
        mImpl->mImage=load(pURI,pFormat,pSize);
    }

    template<typename tFormat>
    CPicture(CImage<tFormat> &&pImage)
        :   mImpl(new SImpl)
    {
        mImpl->mImage=std::move(pImage);
    }

    CAnyImage &Image() const {  return mImpl->mImage;   }

    const CSize_i &Size() const         {   return mImpl->mImage.Size();        }
    EImageFormat Format() const         {   return mImpl->mImage.Format();      }
    const uint8_t *RawBytes() const     {   return mImpl->mImage.RawBytes();    }

    explicit operator bool() const    {   return bool(mImpl); }
    bool operator!() const            {   return !mImpl;      }

private:
    intrusive_ptr<SImpl> mImpl;
};

/*namespace img*/ } /*namespace buola*/ }

#endif
